import { defineStore } from 'pinia';
import { getOrderInfoById } from '@/api/order.js'

export const useGlobalStore = defineStore('global', {
  state: () => ({
    userInfo : wx.getStorageSync('userInfo') || null,
		contractData : null,
		loading : false,
		orderId : null,
		tabIndex: null,
		totalPages: null,
		tripList:[]
  }),
  actions: {
		setUserInfo(data) {
			this.userInfo = data
			wx.setStorageSync('userInfo',data)
		},
		clearUserInfo() {
			this.userInfo = null;
			wx.removeStorageSync('userInfo')
		},
		setTripList(data){
			this.tripList = data
		},		
		setOrderId(id){
			this.orderId = id
		},		
		setTabIndex(index){
			this.tabIndex = index
		},
		setTotalPages(num) {
			this.totalPages = num
		},
		async contractInfoById(id) {
			this.loading = true
			try {
				const data = await getContractInfo(id)
				this.contractData = data.data
				return data.data
			} finally {
				this.loading = false
			}
		}
  }
});